#include "startpage.h"
#include "player/gamemain.h"
#include "GamePage.h"
#include "helppage.h"
using namespace cocos2d;
CCScene *StartPage::scene()
{
	CCScene *scene = NULL;
	do 
	{
		scene = CCScene::create();
		CC_BREAK_IF(!scene);
		StartPage *start_page = StartPage::create();
		scene->addChild(start_page);
	} while (0);
	return scene;
}
bool StartPage::init()
{
	loadResouces();
	setKeypadEnabled(true);
	CCSize size = CCDirector::sharedDirector()->getWinSize();

	GameMain::kScaleX = size.width/800;
	GameMain::kScaleY = size.height/480;
	GameMain::kScale = GameMain::kScaleX<GameMain::kScaleY?GameMain::kScaleX:GameMain::kScaleY;
	CCSprite * back_ground = CCSprite::createWithSpriteFrameName("startpage.jpg");
	back_ground->setScaleX(GameMain::kScaleX);
	back_ground->setScaleY(GameMain::kScaleY);
	back_ground->setAnchorPoint(ccp(0,0));
	back_ground->setPosition(ccp(0,0));
	addChild(back_ground);

	CCSprite *button_bg = CCSprite::createWithSpriteFrameName("buttonbg.png");
	button_bg->setPosition(ccp(GameMain::kScaleX*600,GameMain::kScaleY*100));
	button_bg->setScale(GameMain::kScale);
	addChild(button_bg);


	CCSprite *start_sprite = CCSprite::createWithSpriteFrameName("startbutton.png");
	CCSprite *help_sprite = CCSprite::createWithSpriteFrameName("helpbutton.png");
	CCMenuItemSprite * start = CCMenuItemSprite::create(start_sprite,start_sprite,this,menu_selector(StartPage::start));
	CCMenuItemSprite *help = CCMenuItemSprite::create(help_sprite,help_sprite,this,menu_selector(StartPage::help));
	CCPoint pt = button_bg->getPosition();
	CCPoint ptstart = ccpAdd(pt,CCPoint(-400*GameMain::kScaleX,-175*GameMain::kScaleY));
	CCPoint pthelt = ccpAdd(pt,CCPoint(-420*GameMain::kScaleX,-225*GameMain::kScaleY));
	start->setPosition(ptstart);
	start->setScale(GameMain::kScale);
	help->setPosition(pthelt);
	help->setScale(GameMain::kScale);
	CCMenu *menu = CCMenu::create();
	menu->addChild(start);
	menu->addChild(help);
	addChild(menu);
	return true;
}
void StartPage::start(cocos2d::CCObject *pSender)
{
	CCScene *pScene = GamePage::scene();
	CCDirector::sharedDirector()->replaceScene(pScene);
}
void StartPage::help(cocos2d::CCObject *pSender)
{
	CCScene *pScene = HelpPage::scene();
	CCDirector::sharedDirector()->pushScene(pScene);
}
void StartPage::keyBackClicked()
{
	CCDirector::sharedDirector()->end();
}
void StartPage::loadResouces()
{
	CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("a.plist");
}